<?php
/**
 * Formulaire de mise a jour d'un contact
 * @author Etienne AUDOUIN <etienne.audouin@ingesup.com>
 * @author Adrien MARIANELLI <adrien.marianelli@ingesup.com>
 * @version 1.0
 * @package view_contact_update
 */
if (isset($list) && $list == true) {
    $title = 'Contact(s)';
    echo form_fieldset($title);
    echo '<table id="table_contacts">';
    echo '<tr> <th>Name</th> <th>First Name</th> <th>Mail</th> </tr>';
    foreach ($contacts as $contact) {
        echo '<tr>';
        echo '<td>';
        echo $contact['name'];
        echo '</td>';
        echo '<td>';
        echo $contact['first_name'];
        echo '</td>';
        echo '<td>';
        echo $contact['mail'];
        echo '</td>';
        echo '<td>';
        echo '<a href="?id='.$contact['id'].'">';
        $data = array(
            'name' => 'Edit',
            'id' => 'editContact' . $contact['id'],
            'value' => 'Edit',
            'type' => 'button',
        );
        echo form_input($data);
        echo '</a>';
        echo '</td>';
        echo '</tr>';
    }
    echo '</table>';
    echo form_fieldset_close();
}
if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $formAttributes = array('id' => 'form_updateContact');

    echo form_fieldset('Update contact');
    echo form_open('webnews/doUpdateContact/'.$contact['id'], $formAttributes);
    echo '<table id="table_updateContact">';
// name
    $data = array(
        'name' => 'contactName',
        'id' => 'input_contactName',
        'value' => $contacts[$id]['name']
        );
    echo '<tr>';
    echo '<th>Name</th>';
    echo '<td>' . form_input($data) . '</td>';
    echo '</tr>';

// first name
    $data = array(
        'name' => 'contactFirstName',
        'id' => 'input_contactFirstName',
        'value' => $contacts[$id]['first_name']);

    echo '<tr>';
    echo '<th>First Name</th>';
    echo '<td>' . form_input($data) . '</td>';
    echo '</tr>';

// mail
    $data = array(
        'name' => 'contactMail',
        'id' => 'input_contactMail',
        'value' => $contacts[$id]['mail']);

    echo '<tr>';
    echo '<th>Mail</th>';
    echo '<td>' . form_input($data) . '</td>';
    echo '</tr>';
    echo '</table>';

    echo form_submit(null, 'Update');
    echo form_close();
    echo form_fieldset_close();
}
?>